<?php

namespace App\Http\Controllers\Api\Website;


use App\Http\Resources\AreaCollection;
use App\Http\Resources\ParkCollection;
use App\model\Park;
use App\ParkArea;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Resources\ParkResource;
use App\UserSearch;
use App\Repository\ParkRepository;
use Carbon\Carbon;
use App\model\ImSet;

class ParkController extends Controller
{
    //
    public function index(Request $request,ParkRepository $parkRepository){
        $parkList=$parkRepository->getList($request);
        $user_id = auth('api')->id();
        if(isset($request['search_key'])&&$request['search_key']!=''&&isset($user_id)){
            $now = Carbon::now();
            UserSearch::updateOrCreate(['user_id'=>$user_id,'search_key'=>$request['search_key']],['updated_at'=>$now]);
        }
        return new ParkCollection($parkList);
    }
    public function detail(ParkRepository $parkRepository,$id){
        $park=$parkRepository->detail($id);
        $park['im_set']=ImSet::find(1);
        return new ParkResource($park);
    }
    public function area(){
        $parkArea=ParkArea::all();
        return new AreaCollection($parkArea);
    }
    public function channel($id){
        $parkBaner = Park::with(['parkBaner'])->where('id',$id)->get();
        return new ParkResource($parkBaner);
    }
}
